home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / mpeg / video.h < prev   
C/C++ Source or Header  |  1994-08-01  |  11KB  |  277 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #ifndef VIDEO_H_
  22. #define VIDEO_H_
  23.  
  24. #include <stdio.h>
  25. #include <setjmp.h>
  26.  
  27. typedef unsigned int UINT32;
  28. typedef int          INT32;
  29. typedef unsigned short UINT16;
  30. typedef unsigned char UINT8;
  31.  
  32. /* Define Parsing error codes. */
  33.  
  34. #define SKIP_PICTURE -10
  35. #define SKIP_TO_START_CODE -1
  36. #define PARSE_OK 1
  37.  
  38. #define Exit(n) fprintf(stderr,"exiting from %s at %d\n",__FILE__,__LINE__);\
  39.                 exit(n)
  40. /* Define BOOLEAN, TRUE, and FALSE. */
  41.  
  42. #define BOOLEAN int
  43.  
  44. #ifndef TRUE
  45. #define TRUE 1
  46. #endif
  47.  
  48. #ifndef FALSE
  49. #define FALSE 0
  50. #endif
  51.  
  52. /* Set ring buffer size. */
  53.  
  54. #define RING_BUF_SIZE 5
  55.  
  56. /* Macros for picture code type. */
  57.  
  58. #define I_TYPE 1
  59. #define P_TYPE 2
  60. #define B_TYPE 3
  61.  
  62. /* Start codes. */
  63.  
  64. #define SEQ_END_CODE         0x000001b7
  65. #define SEQ_START_CODE       0x000001b3
  66. #define GOP_START_CODE       0x000001b8
  67. #define PICTURE_START_CODE   0x00000100
  68. #define SLICE_MIN_START_CODE 0x00000101
  69. #define SLICE_MAX_START_CODE 0x000001af
  70. #define EXT_START_CODE       0x000001b5
  71. #define USER_START_CODE      0x000001b2
  72.  
  73. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  74.  
  75. #define MB_QUANTUM 100
  76.  
  77. /* Macros used with macroblock address decoding. */
  78.  
  79. #define MB_STUFFING 34
  80. #define MB_ESCAPE 35
  81.  
  82. /* Lock flags for pict images. */
  83.  
  84. #define DISPLAY_LOCK 0x01
  85. #define PAST_LOCK 0x02
  86. #define FUTURE_LOCK 0x04
  87.  
  88. #define HYBRID_DITHER 0
  89. #define HYBRID2_DITHER 1
  90. #define FS4_DITHER 2
  91. #define FS2_DITHER 3
  92. #define FS2FAST_DITHER 4
  93. #define Twox2_DITHER 5
  94. #define GRAY_DITHER 6
  95. #define FULL_COLOR_DITHER 7
  96. #define NO_DITHER 8
  97. #define ORDERED_DITHER 9
  98. #define MONO_DITHER 10
  99. #define MONO_THRESHOLD 11
  100. #define ORDERED2_DITHER 12
  101. #define MBORDERED_DITHER 13
  102.  
  103. /* External declaration of row,col to zig zag conversion matrix. */
  104.  
  105. extern int scan[][8];
  106.  
  107. /* Temporary definition of time stamp structure. */
  108.  
  109. typedef int TimeStamp;
  110.  
  111. /* Structure with reconstructed pixel values. */
  112.  
  113. typedef struct pict_image {
  114.   unsigned char *luminance;              /* Luminance plane.   */
  115.   unsigned char *Cr;                     /* Cr plane.          */
  116.   unsigned char *Cb;                     /* Cb plane.          */
  117.   unsigned char *display;                /* Display plane.     */
  118.   int locked;                            /* Lock flag.         */
  119.   TimeStamp show_time;                   /* Presentation time. */
  120.  
  121. } PictImage;
  122.  
  123. /* Group of pictures structure. */
  124.  
  125. typedef struct GoP {
  126.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  127.   unsigned int tc_hours;                 /* Hour component of time code.   */
  128.   unsigned int tc_minutes;               /* Minute component of time code. */
  129.   unsigned int tc_seconds;               /* Second component of time code. */
  130.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  131.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  132.                         previous group of pictures.    */
  133.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  134.   char *ext_data;                        /* Extension data.                */
  135.   char *user_data;                       /* User data.                     */
  136. } GoP;
  137.  
  138. /* Picture structure. */
  139.  
  140. typedef struct pict {
  141.   unsigned int temp_ref;                 /* Temporal reference.             */
  142.   unsigned int code_type;                /* Frame type: P, B, I             */
  143.   unsigned int vbv_delay;                /* Buffer delay.                   */
  144.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  145.                         pixel values flag.              */
  146.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  147.   unsigned int forw_f;                   /* Used for vector decoding.       */
  148.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  149.                         pixel values flag.              */
  150.   unsigned int back_r_size;              /* Used in decoding.               */
  151.   unsigned int back_f;                   /* Used in decoding.               */
  152.   char *extra_info;                      /* Extra bit picture info.         */
  153.   char *ext_data;                        /* Extension data.                 */
  154.   char *user_data;                       /* User data.                      */
  155. } Pict;
  156.  
  157. /* Slice structure. */
  158.  
  159. typedef struct slice {
  160.   unsigned int vert_pos;                 /* Vertical position of slice. */
  161.   unsigned int quant_scale;              /* Quantization scale.         */
  162.   char *extra_info;                      /* Extra bit slice info.       */
  163. } Slice;
  164.  
  165. /* Macroblock structure. */
  166.  
  167. typedef struct macroblock {
  168.   int mb_address;                        /* Macroblock address.              */
  169.   int past_mb_addr;                      /* Previous mblock address.         */
  170.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  171.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  172.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  173.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  174.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  175.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  176.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  177.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  178.   unsigned int cbp;                      /* Coded block pattern.             */
  179.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  180.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  181.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  182.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  183.   int recon_right_for_prev;              /* Past right forw. vector.         */
  184.   int recon_down_for_prev;               /* Past down forw. vector.          */
  185.   int recon_right_back_prev;             /* Past right back vector.          */
  186.   int recon_down_back_prev;              /* Past down back vector.           */
  187. } Macroblock;
  188.  
  189. /* Block structure. */
  190.  
  191. typedef struct block {
  192.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  193.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  194.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  195.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  196. } Block;
  197.  
  198. /* Video stream structure. */
  199.  
  200. typedef struct vid_stream {
  201.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  202.   unsigned int v_size;                         /* Vert. size in pixels.      */
  203.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  204.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  205.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  206.   unsigned char picture_rate;                  /* Code for picture rate.     */
  207.   unsigned int bit_rate;                       /* Bit rate.                  */
  208.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  209.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  210.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  211.                           intracoded frames.         */
  212.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  213.                           non intracoded frames.     */
  214.   char *ext_data;                              /* Extension data.            */
  215.   char *user_data;                             /* User data.                 */
  216.   GoP group;                                   /* Current group of pict.     */
  217.   Pict picture;                                /* Current picture.           */
  218.   Slice slice;                                 /* Current slice.             */
  219.   Macroblock mblock;                           /* Current macroblock.        */
  220.   Block block;                                 /* Current block.             */
  221.   int state;                                   /* State of decoding.         */
  222.   int bit_offset;                              /* Bit offset in stream.      */
  223.   unsigned int *buffer;                        /* Pointer to next byte in
  224.                           buffer.                    */
  225.   int buf_length;                              /* Length of remaining buffer.*/
  226.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  227.   int max_buf_length;                          /* Max lenght of buffer.      */
  228.   PictImage *past;                             /* Past predictive frame.     */
  229.   PictImage *future;                           /* Future predictive frame.   */
  230.   PictImage *current;                          /* Current frame.             */
  231.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  232. } VidStream;   
  233.  
  234. /* Declaration of global pointer to current video stream. */
  235.  
  236. extern VidStream *curVidStream;
  237.  
  238. /* Declarataion of global display pointer. */
  239.  
  240. /* Quiet mode flag. */
  241. extern int quietFlag;
  242.  
  243. /* Dither flags external declaration. */
  244. extern char *ditherFlags;
  245.  
  246. /* Definition of Contant integer scale factor. */
  247.  
  248. #define CONST_BITS 13
  249.  
  250. /* Misc DCT definitions */
  251. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  252. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  253.  
  254. #define GLOBAL            /* a function referenced thru EXTERNs */
  255.   
  256. typedef short DCTELEM;
  257. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  258.  
  259.  
  260.  
  261. extern double realTimeStart;
  262. extern int totNumFrames;
  263. extern int loopFlag;
  264. extern int noDisplayFlag;
  265. extern jmp_buf env;
  266. extern jmp_buf errjmp;
  267.  
  268. #ifdef ANALYSIS
  269. extern unsigned int bitCount;
  270. extern int showEachFlag;
  271. extern unsigned int cacheHit[8][8];
  272. extern unsigned int cacheMiss[8][8];
  273. #endif
  274.  
  275.  
  276. #endif /* !video.h_ */
  277.